﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kasutaja", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Kasutaja))]
    public class KasutajaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKasutaja clazz;
        
        public KasutajaSerializer(IKasutaja clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("oma_kood");
            if (clazz.OmaKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaKood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oma_nimi");
            if (clazz.OmaNimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaNimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaNimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oma_eesnimi");
            if (clazz.OmaEesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmaEesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmaEesnimi");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "oma_kood")) {
                goto oma_kood;
            }
            else {
                if ((Reader.LocalName == "oma_nimi")) {
                    goto oma_nimi;
                }
                else {
                    if ((Reader.LocalName == "oma_eesnimi")) {
                        goto oma_eesnimi;
                    }
                    else {
                        return;
                    }
                }
            }
        oma_kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kasutaja>oma_kood");
            }
            clazz.OmaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_kood")).Value;
            goto START;
        oma_nimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kasutaja>oma_nimi");
            }
            clazz.OmaNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_nimi")).Value;
            goto START;
        oma_eesnimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kasutaja>oma_eesnimi");
            }
            clazz.OmaEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oma_eesnimi")).Value;
            goto START;
        }
    }
}
